home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / dtk_demo.zip / FILETYPE.C < prev    next >
C/C++ Source or Header  |  1991-09-12  |  2KB  |  94 lines

  1. /*  FILETYPE.C
  2.  *  checks multiple files for filetype
  3.  *  last mod.: 15-SEP-91
  4.  */
  5.  
  6. #include <STDIO.H>
  7. #include <FCNTL.H>
  8. #include <SYS\TYPES.H>
  9. #include <SYS\STAT.H>
  10. #include <IO.H>
  11. #include <STDLIB.H>
  12. #include <STRING.H>
  13.  
  14. #include <L_FILE.H>
  15. #include <L_DIR.H>
  16.  
  17. char *usage = "\nUse: FILETYPE file_spec";
  18.  
  19. char path[_MAX_PATH_];
  20. char drive[_MAX_DRIVE_];
  21. char dir[_MAX_PATH_];
  22. char file[_MAX_FILE_];
  23.  
  24. /*----------------------------*/
  25. void main(int argc,char *argv[])
  26. {
  27. int i, n, err_flag, result;
  28. File *files;
  29.  
  30. if ( argc < 2 )
  31.     {
  32.     printf(usage);
  33.     exit(0);
  34.     }
  35.  
  36. strupr(argv[1]);
  37.  
  38. split_path(argv[1],drive,dir,NULL,NULL);
  39.  
  40. #if 0
  41.         int read_directory_f(Str_ptr file_spec, Str_ptr attr_spec,
  42.                 File far *files);
  43.         int read_directory(Str_ptr file_spec, Str_ptr attr_spec,
  44.                 File *files);
  45. #endif
  46.  
  47. n = get_input_output_files(argc,argv,&files,NULL,NULL,&err_flag);
  48. /*  this function allocates n*sizeof(File) bytes from
  49.  *  the near heap to hold the File array
  50.  */
  51.  
  52. #if 0
  53. n = read_directory(argv[1],NULL,files);
  54.  */
  55. #endif
  56.  
  57. if ( err_flag )
  58.     {
  59.     switch ( err_flag )
  60.         {
  61.         case -2: printf("Invalid command line parameters.\n"); break;
  62.         case -3: printf("Out of near heap space.\n"); break;
  63.         case -4: break;     /*  ignore this error condition  */
  64.         default: printf("Unknown error.\n");
  65.         }
  66.     }
  67. else if ( !n )
  68.     printf("No files found matching %s.\n",argv[1]);
  69. else
  70.     {
  71.     printf("Files matching %s: %d\n",argv[1],n);
  72.     for ( i=0; i<n; i++ )
  73.         {
  74.         printf("%12s: ",files[i].name);
  75.         make_path(path,drive,dir,files[i].name);
  76.         switch ( result = file_type(path) )
  77.             {
  78.             case  2: printf("text file.\n"); break;
  79.             case  3: printf(".EXE file.\n"); break;
  80.             case  4: printf(".OBJ file.\n"); break;
  81.             case  5: printf("PKZIP file.\n"); break;
  82.             case -3: printf("open error.\n"); break;
  83.             case -4: printf("read error.\n"); break;
  84.             case -5: printf("empty file.\n"); break;
  85.             case -6: printf("file consists of 1 or 2 bytes.\n"); break;
  86.             case -7: printf("null byte found.\n"); break;
  87.             case -8: printf("non-text byte found.\n"); break;
  88.             default: printf("unknown error (%d).\n",result);
  89.             }
  90.         }
  91.     }
  92. }
  93.  
  94.